Fix printing `Fresh` for crates
authorAlex Crichton <alex@alexcrichton.com>
Mon, 23 Mar 2015 18:49:56 +0000 (11:49 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 23 Mar 2015 18:54:47 +0000 (11:54 -0700)
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/ops/cargo_rustc/mod.rs

index 29c56925e32c30b526357a93520b61ff463db9b9..103726755e4e7567456664ecc23fbf7ef9e6b321 100644 (file)
@@ -58,6 +58,7 @@ pub enum Stage {
     Binaries,
     LibraryTests,
     BinaryTests,
+    End,
 }
 
 type Message = (PackageId, Stage, Freshness, CargoResult<()>);
@@ -190,31 +191,44 @@ impl<'a> JobQueue<'a> {
         }
 
         // Print out some nice progress information
-        //
-        // This isn't super trivial becuase we don't want to print loads and
-        // loads of information to the console, but we also want to produce a
-        // faithful representation of what's happening. This is somewhat nuanced
-        // as a package can start compiling *very* early on because of custom
-        // build commands and such.
-        //
-        // In general, we try to print "Compiling" for the first nontrivial task
-        // run for a package, regardless of when that is. We then don't print
-        // out any more information for a package after we've printed it once.
-        let print = !self.printed.contains(&pkg.package_id());
-        if print && total_fresh == Dirty && running.len() > 0 {
-            self.printed.insert(pkg.package_id());
-            match total_fresh {
-                Fresh => try!(config.shell().verbose(|c| {
-                    c.status("Fresh", pkg)
-                })),
-                Dirty => try!(config.shell().status("Compiling", pkg))
-            }
-        }
+        try!(self.note_working_on(config, pkg.package_id(), stage, total_fresh,
+                                  running.len()));
         for msg in running.iter() {
             try!(config.shell().verbose(|c| c.status("Running", msg)));
         }
         Ok(())
     }
+
+    // This isn't super trivial becuase we don't want to print loads and
+    // loads of information to the console, but we also want to produce a
+    // faithful representation of what's happening. This is somewhat nuanced
+    // as a package can start compiling *very* early on because of custom
+    // build commands and such.
+    //
+    // In general, we try to print "Compiling" for the first nontrivial task
+    // run for a package, regardless of when that is. We then don't print
+    // out any more information for a package after we've printed it once.
+    fn note_working_on(&mut self, config: &Config, pkg: &'a PackageId,
+                       stage: Stage, fresh: Freshness, cmds_run: usize)
+                       -> CargoResult<()> {
+        if self.printed.contains(&pkg) { return Ok(()) }
+
+        match fresh {
+            // Any dirty stage which runs at least one command gets printed as
+            // being a compiled package
+            Dirty if cmds_run == 0 => {}
+            Dirty => {
+                self.printed.insert(pkg);
+                try!(config.shell().status("Compiling", pkg));
+            }
+            Fresh if stage == Stage::End => {
+                self.printed.insert(pkg);
+                try!(config.shell().verbose(|c| c.status("Fresh", pkg)));
+            }
+            Fresh => {}
+        }
+        Ok(())
+    }
 }
 
 impl<'a> Dependency for (&'a PackageId, Stage) {
@@ -288,6 +302,13 @@ impl<'a> Dependency for (&'a PackageId, Stage) {
                 base.extend(deps.map(|(id, _)| (id, Stage::Libraries)));
                 base
             }
+
+            // A marker stage to indicate when a package has entirely finished
+            // compiling, nothing is actually built as part of this stage.
+            Stage::End => {
+                vec![(id, Stage::Binaries), (id, Stage::BinaryTests),
+                     (id, Stage::LibraryTests)]
+            }
         }
     }
 }
index d2ccaeb81ca4dc98decc8846271470e89dad0a7c..ab670aaf81e843934c6ff527f42b0a3c7a10fc77 100644 (file)
@@ -278,6 +278,7 @@ fn prepare_init<'a, 'b>(cx: &mut Context<'a, 'b>,
     jobs.queue(pkg, Stage::Binaries);
     jobs.queue(pkg, Stage::LibraryTests);
     jobs.queue(pkg, Stage::BinaryTests);
+    jobs.queue(pkg, Stage::End);
 
     // Prepare the fingerprint directory as the first step of building a package
     let (target1, target2) = fingerprint::prepare_init(cx, pkg, Kind::Target);